package com.ruoyi.service.impl;

import com.ruoyi.domain.BasisPositionUser;
import com.ruoyi.dto.BasisCaseLoadingTaskZhuser;
import com.ruoyi.dto.BasisPositionResourceInfoUser;
import com.ruoyi.dto.BasisTaskZhuser;
import com.ruoyi.mapper.BaseSignalanalysisInfoMapper;
import com.ruoyi.mapper.BasisCaseLoadingTaskMapper;
import com.ruoyi.mapper.BasisPositionUserMapper;
import com.ruoyi.mapper.UserDataMapper;
import com.ruoyi.service.BasisPositionUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BasisPositionUserServiceImpl implements BasisPositionUserService {

    @Autowired
    BasisPositionUserMapper basisPositionUserMapper;

    @Autowired
    UserDataMapper userDataMapper;

    @Autowired
    BasisCaseLoadingTaskMapper basisCaseLoadingTaskMapper;

    @Autowired
    BaseSignalanalysisInfoMapper baseSignalanalysisInfoMapper;

    @Override
    public List<BasisPositionUser> findByLoadingIdFromPositionUser(String loadingId) {
        return basisPositionUserMapper.findByLoadingIdFromPositionUser(loadingId);
    }

    @Override
    public List<BasisPositionUser> findByLoadingIdFromPositionUserRole(String loadingId,Integer deptId) {
        return basisPositionUserMapper.findByLoadingIdFromPositionUserRole(loadingId,deptId);
    }

    @Override
    public boolean addBasisCaseLoadingTaskZhuser(BasisCaseLoadingTaskZhuser basisCaseLoadingTaskZhuser) {
        BasisTaskZhuser basisTaskZhuser = new BasisTaskZhuser();
        basisTaskZhuser.setContent(basisCaseLoadingTaskZhuser.getContent());
        int i = basisPositionUserMapper.addBasisTaskZhuser(basisTaskZhuser);
        if (i > 0){
            basisCaseLoadingTaskZhuser.setTaskId(basisTaskZhuser.getId());
            boolean b = basisPositionUserMapper.addBasisCaseLoadingTaskZhuser(basisCaseLoadingTaskZhuser);
            if (!b) return false;
        }
        return true;
    }

    @Override
    public int configBasisTaskZhuserIssued(Integer taskId) {
        return basisPositionUserMapper.configBasisTaskZhuserIssued(taskId);
    }

    @Override
    public int updateBasisTaskZhuser(BasisCaseLoadingTaskZhuser basisCaseLoadingTaskZhuser) {
        return basisPositionUserMapper.updateBasisTaskZhuser(basisCaseLoadingTaskZhuser);
    }

    @Override
    public boolean configUserContent(BasisPositionResourceInfoUser basisPositionResourceInfoUser) {
        return basisPositionUserMapper.configUserContent(basisPositionResourceInfoUser);
    }

    @Override
    public List<BasisPositionUser> findByLoadingIdFromPositionUserRoleAll(String loadingId) {
        return basisPositionUserMapper.findByLoadingIdFromPositionUserRoleAll(loadingId);
    }

    @Override
    public boolean clearPerformanceTraining(String loadingId) {
//        boolean b = basisPositionUserMapper.clearPerformanceTraining(loadingId);
//        if (b){
//            userDataMapper.delbasisPositionEquipmentUserByLoadingId(loadingId);
//        }
        try{

            basisCaseLoadingTaskMapper.delTaskStatus(loadingId);

            basisCaseLoadingTaskMapper.delscoreIsDel(loadingId);

            baseSignalanalysisInfoMapper.delIsDel(loadingId);

        }catch (Exception e){
            e.printStackTrace();
            return false;
        }


        return true;
    }


}
